from django.contrib.auth.models import User

class SettingsBackend(object):
    def authenticate(self, username=None, password=None):
        login_valid = username
        pwd_valid = password
        if login_valid and pwd_valid:
            try:
                user = User.objects.get(username=username)
            except User.DoesNotExist:
                user = User(username=username)
                user.is_staff = True
                user.is_superuser = False
                user.save()
            return user
        return None
    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None
